package main

import "fmt"

func main() {
	array1 := [5]string{"a", "b", "c", "d", "e"}
	slice1 := array1[0:3]

	slice2 := array1[2:5]
	fmt.Println(slice1)
	fmt.Println(slice2)

	array1[2] = "X"
	fmt.Println(array1)
	fmt.Println(slice1)
	fmt.Println(slice2)

	for k, v := range array1 {
		fmt.Printf("key:%d \t value:%s\n", k, v)
	}
	slice3 := []string{"hujianli1", "hujianli2", "hujianli3"}
	fmt.Println(slice3, len(slice3))
	slice3 = append(slice3, "hujianli4")
	fmt.Println(slice3, len(slice3))
	slice := append(slice3, "xiaojian1", "xiaojian2")
	fmt.Println(slice, len(slice))

	s1 := []string{"s1", "s2"}
	s2 := append(s1, "s2", "s2")
	s3 := append(s2, "s3", "s3")
	s4 := append(s3, "s4", "s4")
	fmt.Println(s1, s2, s3, s4)
	s4[0] = "XZ" //因为s4和s3碰巧都共享 相同的底层数组。
	fmt.Println(s1, s2, s3, s4)

	s1 = []string{"s1", "s1"}
	s1 = append(s1, "s2", "s2")
	s1 = append(s1, "s3", "s3")
	s1 = append(s1, "s4", "s4")
	fmt.Println(s1)

	var intslice []int
	var stringslice []string
	fmt.Printf("intslice: %#v, stringslice: %#v\n", intslice, stringslice)

	fmt.Println(len(intslice))
	intslice = append(intslice, 27)
	fmt.Println(intslice)

	var slicestring []string
	if len(slicestring) == 0 {
		slicestring = append(slicestring, "first item")
	}
	fmt.Printf("%v\n", slicestring)
	fmt.Printf("%#v\n", slicestring)
}
